﻿
@{
    ViewData["Title"] = "AppGoods";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h1>预约商品</h1>
@* 商户查询 *@
<div style="display:flex;width:1000px">
 <div class="layui-form-item">
    <label class="layui-form-label">商户名称</label>
    <div class="layui-input-inline">
        <input type="text" id="goodNames" autocomplete="off" class="layui-input">
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">商品状态</label>
    <div class="layui-input-inline">
        <select id="goodsStatuss" name="goodsStatuss">
        <option value=0 selected>请选择</option>
        <option value=1>上架</option>
        <option value=2>下架</option>
        </select>
    </div>
    </div>

    <div class="layui-form-item">
    <button class="layui-btn" lay-submit lay-filter="demoTable" lay-event="myBtn">查询</button>
    <button class="layui-btn" id="add">添加商品</button>   
   </div>
  </div>


@* 显示商品 *@
<table class="layui-table" id="demoTables" lay-filter="demoTables">
    <tbody>
        <!-- 这里是动态生成的数据 -->
    </tbody>
</table>
 <script type="text/html" id="toolbarDemo">
       <div class="layui-btn-container">
         <button class="layui-btn layui-btn-sm" lay-event="getCheckData">批量删除</button>
         <button class="layui-btn layui-btn-sm" lay-event="GetStateTop">批量上架</button>
         <button class="layui-btn layui-btn-sm" lay-event="GetStateUnder">批量下架</button>
      </div>
  </script>
<div id="demo-laypage-all"></div>
@* 商品操作列 *@
<script type="text/html" id="bardemo">
        <a class="layui-btn layui-btn-xs layui-btn-action"   lay-event="yourFunction">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-action" lay-event="deleteNumber">删除</a>
</script>

<div id="demo-laypage-layout-1"></div>


@* 商品弹出层 *@
<div id="roomTypeAdd" style="display:none">
    <form class="layui-form">
        <h2>基本类型</h2>
        <div class="layui-form-item" style="display:none">
            <label class="layui-form-label"><span style="color:red">*</span>预约商品id</label>
            <div class="layui-input-block">
                <input type="text" name="appGoodId" id="appGoodId" placeholder="预约商品id">
            </div>
        </div>


      <div class="layui-form-item">
          <label class="layui-form-label">预约名称</label>
          <div class="layui-input-block">
             <input type="text" name="appGoodName" id="appGoodName" lay-verify="required|maxlength" lay-maxlength="18"   lay-reqtext="请填写预约名称" autocomplete="off" class="layui-input">
          </div>
      </div>

   
    <div class="layui-form-item">
      <label class="layui-form-label">商品标签</label>
      <div class="layui-input-block" style="width:30%">
          <select name="goodLableId" id="goodLableId"  lay-search="required">
              <option value="">请选择</option>
          </select>
          <button class="layui-btn" type="button" id="AddLable2" lay-filter="AddLable2">新增</button>
      </div>
   </div>

     <div class="layui-upload-drag" style="display: block;" id="ID-upload-demo-drag">
      <i class="layui-icon layui-icon-upload "></i> 
      <div>点击上传，或将文件拖拽到此处</div>
      <div class="layui-hide" id="ID-upload-demo-preview">
        <hr> <img src="" alt="上传成功后渲染" style="width: 100px; height: 100px;"  name="appGoodPhoto" id="appGoodPhoto">
      </div>
    </div>

  
<div class="layui-form-item">
    <label class="layui-form-label">商品状态</label>
    <div class="layui-input-block">
        <input type="checkbox" name="goodsStatus" lay-skin="switch" lay-text="上架|下架">
    </div>
</div>



    <div class="layui-form-item">
      <label class="layui-form-label">预约简介</label>
      <div class="layui-input-block">
        <textarea name="appGoodInfo" id="appGoodInfo" lay-verify="required" placeholder="输入内容不超过50字" class="layui-textarea"></textarea>
      </div>
    </div>

     <div class="layui-form-item" >
      <label class="layui-form-label">分类设置</label>
      <div class="layui-input-block" style="width:30%">
          <select name="typeId" id="typeId"  lay-search="required">
              <option value="">请选择</option>
          </select>  
      </div>
   </div>

    <h2>预约信息</h2>
    <div class="layui-form-item">
    <label class="layui-form-label">时段类型</label>
    <div class="layui-input-block">
        <input type="radio" name="timeType" id="timeType" value="0" title="全天" lay-filter="radioFilter">
        <input type="radio" name="timeType" id="timeType" value="1" title="时段" lay-filter="radioFilter">
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">收费方式</label>
    <div class="layui-input-block">
        <input type="radio" name="moneyType" id="moneyType" value="0" title="预约收费" lay-filter="radioFilter">
        <input type="radio" name="moneyType" id="moneyType" value="1" title="到店付费" lay-filter="radioFilter">
    </div>
</div>


       <div class="layui-form-item">
          <label class="layui-form-label">预约文案</label>
          <div class="layui-input-block">
             <input type="text" name="appGoodTitle" id="appGoodTitle" lay-verify="required"  placeholder="立即预约"   autocomplete="off" class="layui-input">
          </div>
      </div>

      <div class="layui-form-item">
          <label class="layui-form-label">预约单位</label>
          <div class="layui-input-block">
             <input type="text" name="appGoodUnit" id="appGoodUnit" lay-verify="required"  placeholder="人"   autocomplete="off" class="layui-input">
          </div>
      </div>
       


    <div class="layui-form-item">
     <label class="layui-form-label">可用抵扣</label>
     <div class="layui-input-block">
        <input type="checkbox" name="appGoodDikou" id="appGoodDikou" value="积分" title="积分">
        <input type="checkbox" name="appGoodDikou" id="appGoodDikou"  value="余额" title="余额">
     </div>
   </div>

   <div class="layui-form-item">
     <label class="layui-form-label">可用优惠</label>
     <div class="layui-input-block">
        <input type="checkbox" name="appGoodChecp" id="appGoodChecp" value="会员折扣" title="会员折扣">
        <input type="checkbox" name="appGoodChecp" id="appGoodChecp"  value="优惠卷" title="优惠卷">
     </div>
   </div>


   <div class="layui-form-item">
          <label class="layui-form-label">是否限购</label>
          <div class="layui-input-block">
             <input type="text" name="isBuy" id="isBuy" lay-verify="required"  placeholder="不填不限购"   autocomplete="off" class="layui-input">
          </div>
      </div>

    <h2>其他信息</h2>
    <div class="layui-form-item">
       <label class="layui-form-label">下架设置</label>
       <div class="layui-input-block">
         <input type="checkbox" name="dropSet" id="dropSet" value="定时下架" title="定时下架" lay-filter="checkboxFilter">
       </div>
        <div id="content_定时下架" >
          <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">选择日期</label>
             <div class="layui-input-inline">
               <input type="text" class="layui-input" id="dropTime" name="dropTime" placeholder="yyyy-MM-dd HH:mm:ss">
             </div>
           </div>
          </div>

        </div>
    </div>
   

  <div class="layui-form-item">
    <label class="layui-form-label">手机号码</label>
    <div class="layui-input-block">
        <input type="checkbox" name="isPhone" lay-skin="switch" lay-text="开启短信验证/关闭短信验证">
    </div>
</div>
    

   <h2>分享设置</h2>
    <div class="layui-form-item">
          <label class="layui-form-label">分享标题</label>
          <div class="layui-input-block">
             <input type="text" name="shareTitel" id="shareTitel" lay-verify="required|maxlength" lay-maxlength="18" placeholder="例：商品名称"   autocomplete="off" class="layui-input">
          </div>
      </div>

    <div class="layui-form-item">
      <label class="layui-form-label">分享描述：</label>
      <div class="layui-input-block">
        <textarea name="shareDesc" id="shareDesc" lay-verify="required" placeholder="给你分享一个商品，快来看吧！" class="layui-textarea"></textarea>
      </div>
    </div>

     <div class="layui-upload-drag" style="display: block;" id="ID-upload-demo-drag2">
      <i class="layui-icon layui-icon-upload "></i> 
      <div>点击上传，或将文件拖拽到此处</div>
      <div class="layui-hide" id="ID-upload-demo-preview2">
        <hr> <img src="" alt="上传成功后渲染" style="width: 100px; height: 100px;"  name="sharePhotos" id="sharePhotos">
      </div>
    </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="reset" class="layui-btn layui-btn-primary">取消</button>
                <button id="adds"  class="layui-btn" lay-submit lay-filter="submitForm">确认</button>
                <button id="edit" class="layui-btn" lay-submit lay-filter="xiuForm">修改</button>
            </div>
        </div>

    </form>
</div>


@* 标签弹出层 *@
<div id="lableadd" style="display:none">
    <form class="layui-form">
        <div class="layui-form-item" style="display:none">

            <label class="layui-form-label"><span style="color:red">*</span>商品标签id</label>
            <div class="layui-input-block">
                <input type="text" name="goodLableId" id="goodLableId" placeholder="商品标签id">
            </div>
        </div>


      <div class="layui-form-item">
          <label class="layui-form-label">商户名称</label>
          <div class="layui-input-block">
             <input type="text" name="goodLableName" id="editgoodLableName"  placeholder=""  lay-reqtext="" autocomplete="off" class="layui-input">
          </div>
      </div>
 
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="reset" class="layui-btn layui-btn-primary">取消</button>
                <button id="edit" class="layui-btn" lay-submit lay-filter="ADDLable">添加</button>
            </div>
        </div>

    </form>
</div>

<script>

    function getSelectedIds() {
    var checkstatus = layui.table.checkstatus('demoTable'); // 'demo'为表格的基础参数 id
    // console.log(checkstatus.data); // 获取选中行的数据，即多个行对象
    // console.log(checkstatus.data.length); // 获取选中行数量，可作为是否有选中行的条件
    // console.log(checkstatus.isall); // 表格是否全选

    if (checkstatus.data.length > 0) {
        var idsArray = [];
        for (var i = 0; i < checkstatus.data.length; i++) {
            idsArray.push(checkstatus.data[i].roomId); // 假设每行数据中有一个名为'id'的字段用于存储行的标识
        }
        var ids = idsArray.toString();
        // console.log(ids);
        alert(ids);
    } else {
        alert("请至少选择一行");
    }
}

layui.use(['table', 'jquery', 'layer', 'form', 'laypage', 'element', 'util', 'laydate','upload'], function () {
    var table = layui.table;
    var $ = layui.jquery;
    var form = layui.form;
    var layer = layui.layer;
    var laypage = layui.laypage;
    var element = layui.element;
    var util = layui.util;
    var laydate = layui.laydate;
    var upload=layui.upload;

    $(function () {
        show();
        goodlable();
        goodtype();
    })
   function goodlable(){
         // //绑定下拉框(商品标签)
    $.ajax({
        url: 'http://localhost:5174/api/Goods/GetAllGoodlable',
        type: 'GET',
        dataType: 'json',
        success: function (response) {
            var form = layui.form;
            form.render('select');
            var select = $('#goodLableId');
            select.find('option').remove(); // 清空原有的选项
            $.each(response.data, function (index, item) {
                select.append($('<option>', {
                    value: item.goodLableId,
                    text: item.goodLableName
                }));
            });
            form.render('select'); // 重新渲染
        },
        error: function (error) {
            console.error('请求失败：', error);
        }
    });
   }
  
    
   function goodtype(){
         // //绑定下拉框（商品分类）
    $.ajax({
        url: 'http://localhost:5174/api/Goods/GetAllType',
        type: 'GET',
        dataType: 'json',
        success: function (response) {
            var form = layui.form;
            form.render('select');
            var select = $('#typeId');
            select.find('option').remove(); // 清空原有的选项
            $.each(response.data, function (index, item) {
                select.append($('<option>', {
                    value: item.typeId,
                    text: item.typeName
                }));
            });
            form.render('select'); // 重新渲染
        },
        error: function (error) {
            console.error('请求失败：', error);
        }
    });
   }



    form.render();

    // 日期时间选择器 - 日期和时间选择器同时显示（全面板）
   laydate.render({
    elem: '#sGuTime',
    type: 'datetime',
    fullPanel: true // 2.8+
  });
    laydate.render({
    elem: '#eGuDate',
    type: 'datetime',
    fullPanel: true // 2.8+
  });
  laydate.render({
    elem: '#dropTime',
    type: 'datetime',
    fullPanel: true // 2.8+
  });

  //单选框
   form.on('radio(radioFilter)', function(data){
        var selectedValue = data.value;
        console.log(selectedValue);  // 这里获取到选中的值
    });

    form.render();

   
    //定义变量
    var from = {
        appGoodName: "",
        goodsStatus:$("#goodsStatuss").val(),
        index: 1,
        pagesize: 15
    }
    var total = 0;
    //显示
    function show() {
        $.ajax({
            url: 'http://localhost:5174/api/AppGood/GetAppGoodShow',
            type: 'post',
            contentType: "application/json",
            data: JSON.stringify(from),
            headers: {
                "Authorization": "Bearer " + localStorage.getItem('token')
            },
            async: true,
            success: res => {
                total = res.data.total;
                table.render({
                    elem: '#demoTables',
                    data: res.data.data,
                    toolbar: '#toolbarDemo',
                    cols: [[
                        { field: 'ck', type: 'checkbox', },
                        { field: 'appGoodName', title: '商品名称' },
                        { field: 'appGoodUnit',  title: '预约人数' },
                        { field: 'goodsStatus', title: '商品状态',templet: function (d) {
                       if (d.goodsStatus == 1) { 
                            return "<input type='checkbox' lay-skin='switch' lay-text='已上架' checked>";
                       } else if (d.goodsStatus == 2) { 
                            return "<input type='checkbox' lay-skin='switch' lay-text='已下架'>";
                       }
                      }},
                        { toolbar: '#bardemo', title: '操作' }
                    ]],
                    page:true,
                    limits:[5,10,15],
                    limit:5
                });
            },
            error: function (error) {
                console.error(error);
            }
        })
    }


    // 工具栏事件（批量删除）
  table.on('toolbar(demoTables)', function(obj){
    
    console.log(obj.config.data)
     var id=obj.config.id;
     var checkStatus = table.checkStatus(id);
     var othis = lay(this);
     switch(obj.event){
       case 'getCheckData':
                  var data=  checkStatus.data; 
                  checkids=[];
                  console.log(checkids);
                  checkStatus.data.forEach(function(row){
                        checkids.push(row.appGoodId);
                    })
                      console.log(checkids);
                    $.ajax({
                        url: 'http://localhost:5174/api/AppGood/GetDelAppGood',
                        type: 'post',
                        contentType: "application/json",
                        data: JSON.stringify({ appGoodId: checkids }),
                        headers: {
                            "Authorization": "Bearer " + localStorage.getItem('token')
                        },
                        success: function (res) {
                            if (res.code > 0) {
                                layer.msg("删除成功");
                                show()
                            }

                            // 删除成功后的操作
                        }
                    });

        //layer.alert(layui.util.escape(JSON.stringify(data)));
        break;
      case 'getData':
        var getData = table.getData(id);
        console.log(getData);
        layer.alert(layui.util.escape(JSON.stringify(getData)));
        break;
         case 'GetStateTop':
                  var data=  checkStatus.data; 
                  checkids=[];
                  console.log(checkids);
               layer.confirm('您确定要批量上架这些商品吗？', {
               btn: ['确定', '取消']
               }, function () {
                  checkStatus.data.forEach(function(row){
                        checkids.push(row.appGoodId);
                    })
                      console.log(checkids);
                    $.ajax({
                        url: 'http://localhost:5174/api/AppGood/GetAppGoodUpdState',
                        type: 'post',
                        contentType: "application/json",
                        data: JSON.stringify({ 
                            "appGoodId": checkids,"goodsStatus": 1
                        }),
                        headers: {
                            "Authorization": "Bearer " + localStorage.getItem('token')
                        },
                        success: function (res) {
                            if (res.code > 0) {
                                layer.msg("批量上架成功");
                                show()
                            }
                        }
                    });
                    }, function () {
        layer.msg('您已取消批量上架操作');
    });
        break;
        case 'GetStateUnder':
                  var data=  checkStatus.data; 
                  checkids=[];
                  console.log(checkids);
               layer.confirm('您确定要批量下架这些商品吗？', {
               btn: ['确定', '取消']
               }, function () {
                  checkStatus.data.forEach(function(row){
                        checkids.push(row.appGoodId);
                    })
                      console.log(checkids);
                    $.ajax({
                        url: 'http://localhost:5174/api/AppGood/GetAppGoodUpdState',
                        type: 'post',
                        contentType: "application/json",
                        data: JSON.stringify({
                          "appGoodId": checkids,"goodsStatus": 2
                        }),
                        headers: {
                            "Authorization": "Bearer " + localStorage.getItem('token')
                        },
                        success: function (res) {
                            if (res.code > 0) {
                                layer.msg("批量下架成功");
                                show()
                            }

                            // 删除成功后的操作
                        }
                    });
                 }, function () {
                layer.msg('您已取消批量下架操作');
            });
        break;
    };
  });


    //查询
    $(document).on('click', '[lay-event="myBtn"]', function () {

        from.goodName = $("#goodNames").val()
        from.goodsStatus = $("#goodsStatuss").val()
        // 处理点击事件的逻辑
        show();
    });

    //反选
    // 监听全选复选框
    var selectedValues = [];
    form.on('checkbox(ck)', function (data) {
        var isChecked = data.elem.checked;

        console.log('选中的值:', data.elem.checked);
        var checkboxes = document.querySelectorAll('#dataTable tbody input[type="checkbox"]');
        checkboxes.forEach(function (checkbox) {
            checkbox.checked = isChecked;
            if (checkbox.checked) {
                selectedValues.push(checkbox.value.appGoodId);
            }
        });
        console.log('选中的值:', data.elem.checked);
    });


     var photoUrl = ""
    // 上传图片（上面）
    upload.render({
        elem: '#ID-upload-demo-drag',
        url: 'http://localhost:5174/api/Store/Upload',
        file: 'appGoodPhoto', // 实际使用时改成您自己的上传接口即可。
        done: function (res) {
            layer.msg('上传成功');
            $('#ID-upload-demo-preview').removeClass('layui-hide')
                .find('img').attr('src', 'http://localhost:5174/' + res.msg);
            photoUrl = 'http://localhost:5174/' + res.msg;
            console.log(photoUrl)
            console.log(res.msg)
        }
    });


      var photoUrl2 = ""
    // 上传图片（下面）
    upload.render({
        elem: '#ID-upload-demo-drag2',
        url: 'http://localhost:5174/api/Store/Upload',
        file: 'sharePhotos', // 实际使用时改成您自己的上传接口即可。
        done: function (res) {
            layer.msg('上传成功');
            $('#ID-upload-demo-preview2').removeClass('layui-hide')
                .find('img').attr('src', 'http://localhost:5174/' + res.msg);
            photoUrl2 = 'http://localhost:5174/' + res.msg;
            console.log(photoUrl2)
            console.log(res.msg)
        }
    });


      document.querySelector('[name="goodsStatus"]').checked = true;
      form.render();

    //添加商品
    form.on('submit(submitForm)', function (data) {
       console.log(data.field);      
     
       if(data.field.goodsStatus=="true"){
           data.field.goodsStatus=1;
       }
       else 
       {
           data.field.goodsStatus=2;
       }
       if(data.field.isPhone=="true"){
           data.field.isPhone=1;
       }
       else 
       {
           data.field.isPhone=2;
       }
    
        //可用抵扣
        var checkedValues = [];
        $("input[name='appGoodDikou']:checked").each(function () {
            checkedValues.push($(this).val());
        });
        data.field.appGoodDikou = checkedValues.toString();
        //可用优惠
        var checkedValues2 = [];
        $("input[name='appGoodChecp']:checked").each(function () {
            checkedValues2.push($(this).val());
        });
        data.field.appGoodChecp = checkedValues2.toString();
        data.field.appGoodPhoto = photoUrl;
        data.field.sharePhotos = photoUrl2;
        data.elem.disabled = true;//防止重复提交
        $.ajax({
            url: 'http://localhost:5174/api/AppGood/GetAppGoodAdd',
            type: 'post',
            contentType: "application/json",
            data: JSON.stringify(data.field),
            success: function (res) {
                // 添加成功后的操作
                if (res.code > 0) {
                    layer.msg("添加成功");
                    show()
                }
            }
        });
        return false;
    });

    //弹出层
    $(".layui-btn").click(function () {
        var id = $(this).attr('id');
        if (id === "add") {
            $("#edit").hide();
            $("#adds").show();
            
            var index = layer.open({
                type: 1,
                area: ['630px', '360px'],
                shade: false, // 不显示遮罩
                content: $('#roomTypeAdd'), // 捕获的元素
                end: function () {
                    // layer.msg('关闭后的回调', {icon:6});
                }
            });
        }
    });


    //反填商户编辑 （单删）添加商户
    table.on('tool()', function (obj) {
        console.log(obj)
        var data = obj.data; // 获取当前行数demoTable据
        var layEvent = obj.event; // 获取 lay-event 对应的值
        console.log(data)
        $.ajax({
            url: 'http://localhost:5174/api/AppGood/GetFindAppGood',  // 替换成实际的接口地址
            type: 'GET',
            data: { id: data.appGoodId },  // 传递的参数
            success: function (data) {

                // 将数据填充到表单中
                document.getElementById('appGoodId').value = data.data.appGoodId;
                $("#appGoodName").val(data.data.appGoodName)
                $('#appGoodPhoto').attr('src', data.data.appGoodPhoto);
                 // 设置单选框的选中状态
                $('input[name="goodsStatus"][value="' + data.data.goodsStatus + '"]').prop('checked', true);
                $("#goodLableId").val(data.data.goodLableId);
                $("#goodLableName").val(data.data.goodLableName);
                $("#appGoodInfo").val(data.data.appGoodInfo);
                $("#typeId").val(data.data.typeId);
                $("#typeName").val(data.data.typeName);
               //时段类型
                $('input[name="timeType"][value="' + data.data.timeType + '"]').prop('checked', true);
               //收费方式
                $('input[name="moneyType"][value="' + data.data.moneyType + '"]').prop('checked', true);

                $("#appGoodUnit").val(data.data.appGoodUnit);
                $("#appGoodDikou").val(data.data.appGoodDikou);
                // 模拟后台数据，假设 goodDikou 的值为 ["积分", "余额"]
                var dikouValues = ["积分", "余额"]; // 从后台获取的值
                 // 遍历后台数据，设置复选框的选中状态
                 layui.each(dikouValues, function(index, value){
                   $('input[name="appGoodDikou"][value="' + value + '"]').prop('checked', true);
                 });
                // 重新渲染表单（如果需要）
                form.render('checkbox');
                 // 模拟后台数据，假设 appGoodChecp 的值为 ["积分", "余额"]
                 var dikouValues = ["会员折扣", "优惠卷"]; // 从后台获取的值
               // 遍历后台数据，设置复选框的选中状态
               layui.each(dikouValues, function(index, value){
                 $('input[name="appGoodChecp"][value="' + value + '"]').prop('checked', true);
               });
               // 重新渲染表单（如果需要）
                form.render('checkbox');
                $("#isBuy").val(data.data.isBuy);
                // 设置单选框的选中状态
              
                
                $("#restRule").val(data.data.restRule);
                // 模拟后台数据，假设 dropSet 的值为 ["下架"]
                var dikouValues = ["定时下架"]; // 从后台获取的值
                 // 遍历后台数据，设置复选框的选中状态
                 layui.each(dikouValues, function(index, value){
                   $('input[name="dropSet"][value="' + value + '"]').prop('checked', true);
                 });
                // 重新渲染表单（如果需要）
                form.render('checkbox');
                $("#dropTime").val(data.data.dropTime);
                 // 设置单选框的选中状态
                $('input[name="isPhone"][value="' + data.data.isPhone + '"]').prop('checked', true);
                $("#shareTitel").val(data.data.shareTitel);
                $("#shareDesc").val(data.data.shareDesc);
                $('#sharePhotos').attr('src', data.data.sharePhotos);
                document.getElementById('ID-upload-demo-preview').classList.remove('layui-hide');
                document.getElementById('ID-upload-demo-preview2').classList.remove('layui-hide');

              
              
               },
            error: function (xhr, status, error) {
                console.error('Error fetching user data:', error);
                // 处理错误情况
             }

        });
        //修改商户
        form.on('submit(xiuForm)', function (data) {
            console.log(JSON.stringify(data.field));
           if(data.field.goodsStatus=="on"){
              data.field.goodsStatus=1;
           }
           else 
           {
              data.field.goodsStatus=2;
           }

           if(data.field.isPhone=="true"){
             data.field.isPhone=1;
           }
           else 
          {
             data.field.isPhone=2;
          }
            //可用抵扣
        var checkedValues = [];
        $("input[name='appGoodDikou']:checked").each(function () {
            checkedValues.push($(this).val());
        });
        data.field.appGoodDikou = checkedValues.toString();
        //可用优惠
        var checkedValues2 = [];
        $("input[name='appGoodChecp']:checked").each(function () {
            checkedValues2.push($(this).val());
        });
        data.field.appGoodChecp = checkedValues2.toString();
        data.field.goodImage = photoUrl;
        data.field.sharePhotos = photoUrl2;
    
        data.elem.disabled = true;//防止重复提交
            
            $.ajax({
                url: 'http://localhost:5174/api/AppGood/GetUpdAppGood',
                type: 'post',
                contentType: "application/json",
                data: JSON.stringify(data.field),

                success: function (res) {

                    // 添加成功后的操作
                    if (res.code > 0) {
                        layer.msg("修改成功");
                        var index = layer.getFrameIndex('index'); // 获取弹出层的索引
                        layer.close(index);
                    }
                }
            });
            return false;
        });

        if (obj.event === 'yourFunction') {
            $("#edit").show();
            $("#adds").hide();
            //编辑按钮的处理逻辑
            //var roomid = obj.roomId
            layer.open({
                title: '编辑 - id:' + data.appGoodId,
                type: 1,
                shade: false, // 不显示遮罩
                area: ['80%', '80%'],
                content: $('#roomTypeAdd'),
                end: function () {
                    // layer.msg('关闭后的回调', {icon:6});
                }
            });
            //在这里进行编辑相关的操作，例如打开编辑模态框、发送编辑请求等
            console.log('编辑按钮被点击，行数据为:', data);
        }
        else if (layEvent === 'deleteNumber') {

            layer.confirm('确定要删除该行数据吗？', function (index) {
                // 执行删除操作...
                var myArray = [];
                myArray.push(obj.data.appGoodId)
                console.log(myArray)
                $.ajax({
                    url: 'http://localhost:5174/api/AppGood/GetDelAppGood',
                    type: 'post',
                    contentType: "application/json",
                    data: JSON.stringify({ appGoodId: myArray }),
                    headers: {
                        "Authorization": "Bearer " + localStorage.getItem('token')
                    },
                    success: function (res) {
                        if (res.code > 0) {
                            layer.msg("删除成功");
                            show()
                        }

                        // 删除成功后的操作
                    }
                });
                layer.close(index);
            });
        }
    });



});
</script>




